package com.example.practice.utls;


import com.example.practice.entity.User;
import com.example.practice.entity.userRole;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SecurityUtils {
    /**
     * 获取当前用户
     *
     * @return
     */
    public static User getCurrentUserInfo() {
        User userInfo = SessionUtils.getCurrentUserInfo();
        //模拟登录
        if (userInfo == null) {
            userInfo = new User();
            userInfo.setAccount("模拟");
        }

        return userInfo;
    }

    public static userRole getUserInfo() {
        User userInfo = SessionUtils.getCurrentUserInfo();
        userRole userInfoDTO = new userRole();
        //模拟登录
        if (userInfo == null) {
//            userInfo = new User();
//            userInfo.setAccount("模拟用户");
//            userInfoDTO.setId(1);
//            userInfoDTO.setRole(1);
        }else{
            userInfoDTO.setId(userInfo.getId());
            userInfoDTO.setAccount(userInfo.getAccount());
            userInfoDTO.setRole(userInfo.getRole());
        }

        return userInfoDTO;
    }
}
